package cn.itcast.web.controller.system;

import cn.itcast.domain.system.Dept;
import cn.itcast.domain.system.Role;
import cn.itcast.domain.system.SysLog;
import cn.itcast.service.system.DeptService;
import cn.itcast.service.system.RoleService;
import cn.itcast.service.system.SysLogService;
import cn.itcast.web.controller.BaseController;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/system/log")
public class SysLogController extends BaseController {
    @Autowired
    private SysLogService sysLogService;

    /**
    *系统日记：显示系统日记列表
    *功能入口：aside.jsp点击系统日记管理
    *请求地址：http://locahost:8080/system/log/list.do
    *响应地址：http://locahost:8080/WEB-INF/pages/system/log/log-list.jsp系统日记
    */

    @RequestMapping("/list")
    public String list(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5") Integer pageSize){
        String companyId = getLoginCompanyId();
        PageInfo<SysLog> pageInfo = sysLogService.findByPage(companyId, pageNum, pageSize);
        request.setAttribute("pageInfo",pageInfo);
        return "system/log/log-list";
    }


    /**
    *系统日记：进入系统日记添加页面
    *功能入口：sysLog-list.jsp点击新建
    *请求地址：http://locahost:8080//system/sysLog/toAdd.do
    *响应处理：查询所有部門信息放入请求域以便回显在下拉列表
     * 响应地址：http://locahost:8080/WEB-INF/pages/system/sysLog/sysLog-add.jsp
     *
    */
    @Autowired
    private DeptService deptService;

    @RequestMapping("/toAdd")
    public String toAdd(){
        List<Dept> deptList = deptService.findAll(getLoginCompanyId());
        request.setAttribute("deptList",deptList);
        return "system/sysLog/sysLog-add";
    }












}
